<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="流程名称" prop="name">
        <el-select v-model="queryParams.applyID">
          <el-option label="请假申请" value="leaveApply"></el-option>
          <el-option label="离职申请" value="quitApply"></el-option>
          <el-option label="维修申请" value="repairApply"></el-option>
          <el-option label="会议室预定申请" value="meetingApply"></el-option>
          <el-option label="违纪申请" value="violativeApply"></el-option>
          <el-option label="公文申请" value="documentApply"></el-option>
          <el-option label="访客申请" value="visitApply"></el-option>
          <el-option label="部门用人申请" value="usePersonApply"></el-option>
          <el-option label="学生请假(代提)" value="studentLeaveWithdrawal"></el-option>
          <el-option label="学生请假(自提)" value="studentLeaveSelfApply"></el-option>
          <el-option label="物品申购申请" value="goodsBuyApply"></el-option>
          
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-tabs v-model="activeName" @tab-click="handleClick">
      
        <el-tab-pane label="待处理申请单" name="first">
          <el-table v-loading="loading" :data="deployList">
            <el-table-column label="流程ID" prop="processDefinitionId" align="center" :show-overflow-tooltip="true">
              <template slot-scope="scope">
                <label v-if="scope.row.processDefinitionId.indexOf('leaveApply')>=0">请假申请</label>
                <label v-if="scope.row.processDefinitionId.indexOf('quitApply')>=0">离职申请</label>
                <!-- <label v-if="scope.row.processDefinitionId.indexOf('WeijiApply')>=0">违纪申请</label> -->
                <label v-if="scope.row.processDefinitionId.indexOf('repairApply')>=0">维修申请</label>
                <label v-if="scope.row.processDefinitionId.indexOf('meetingApply')>=0">会议室预定申请</label>
                <label v-if="scope.row.processDefinitionId.indexOf('violativeApply')>=0">违纪申请</label>
                <label v-if="scope.row.processDefinitionId.indexOf('documentApply')>=0">公文申请</label>
                <label v-if="scope.row.processDefinitionId.indexOf('visitApply')>=0">访客申请</label>
                <label v-if="scope.row.processDefinitionId.indexOf('usePersonApply')>=0">部门用人申请</label>
                <label v-if="scope.row.processDefinitionId.indexOf('studentLeaveWithdrawal')>=0">学生请假(代提)</label>
                <label v-if="scope.row.processDefinitionId.indexOf('goodsBuyApply')>=0">物品申购申请</label>
                <label v-if="scope.row.processDefinitionId.indexOf('studentLeaveSelfApply')>=0">学生请假(自提)</label>
                
                
              </template>
            </el-table-column>
        <el-table-column label="审批节点" align="center" prop="name" :show-overflow-tooltip="true" />
        <el-table-column label="是否审批" align="center" :show-overflow-tooltip="true" >
          <template >
            <el-tag type="info">未审批</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="创建时间" align="center" prop="createTime" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            {{ parseTime(scope.row.createTime) }}
          </template>
        </el-table-column>

        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-tooltip class="item" effect="dark" content="审批" placement="top">
              <el-button size="mini" circle icon="el-icon-edit" @click="handleApply(scope.row)" />
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />
        </el-tab-pane>
      
      


      <el-tab-pane label="已处理申请单" name="second">
        <el-table v-loading="loading" :data="deployList">
      <el-table-column label="流程ID" prop="processDefinitionId" align="center" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <label v-if="scope.row.processDefinitionId.indexOf('leaveApply')>=0">请假申请</label>
          <label v-if="scope.row.processDefinitionId.indexOf('quitApply')>=0">离职申请</label>
          <!-- <label v-if="scope.row.processDefinitionId.indexOf('WeijiApply')>=0">违纪申请</label> -->
          <label v-if="scope.row.processDefinitionId.indexOf('repairApply')>=0">维修申请</label>
          <label v-if="scope.row.processDefinitionId.indexOf('meetingApply')>=0">会议室预定申请</label>
          <label v-if="scope.row.processDefinitionId.indexOf('violativeApply')>=0">违纪申请</label>
          <label v-if="scope.row.processDefinitionId.indexOf('documentApply')>=0">公文申请</label>
          <label v-if="scope.row.processDefinitionId.indexOf('visitApply')>=0">访客申请</label>
          <label v-if="scope.row.processDefinitionId.indexOf('usePersonApply')>=0">部门用人申请</label>
          <label v-if="scope.row.processDefinitionId.indexOf('studentLeaveWithdrawal')>=0">学生请假(代提)</label>
          <label v-if="scope.row.processDefinitionId.indexOf('goodsBuyApply')>=0">物品申购申请</label>
          <label v-if="scope.row.processDefinitionId.indexOf('studentLeaveSelfApply')>=0">学生请假(自提)</label>
        </template>
      </el-table-column>

      <el-table-column label="审批节点" align="center" prop="name" :show-overflow-tooltip="true" />
      <el-table-column label="是否审批" align="center" :show-overflow-tooltip="true" >
        <template >
          <el-tag type="success">已处理</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          {{ parseTime(scope.row.createTime) }}
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-tooltip class="item" effect="dark" content="查看" placement="top">
            <el-button size="mini" circle icon="el-icon-view" @click="handleApply(scope.row)" />
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
      </el-tab-pane>
    </el-tabs>

    

    
    <el-dialog title="流程审批" :visible.sync="dialogVisible" width="70%" :before-close="handleClose">
      <!--请假详情-->
      <leave-apply-detail :leaveFormData="leaveFormData" v-if="isShowLeave"></leave-apply-detail>
      <!--离职详情-->
      <quit-apply-detail :quitFormData="quitFormData" v-if="isShowQuit"></quit-apply-detail>
      <!--用人申请-->
      <usePersonDetail :usePersonFormData = "usePersonFormData" v-if="isShowUsePerson"></usePersonDetail>
      <!--学生请假（代提）-->
      <studentLeaveWithdrawalDetail :leaveFormData="studentLeaveFormData" v-if="isShowStudentLeave"></studentLeaveWithdrawalDetail>
      <!--学生请假（自提）-->
      <studentLeaveSelfDetail :leaveFormData="studentLeaveSelfFormData" v-if="isShowStudentSelfLeave"></studentLeaveSelfDetail>
      <!--违纪详情-->
      <weijiApplyDetail :weijiFormData="weijiFormData" :arr="arr" :fileList="fileList" :gradeOptions="gradeOptions"
        :statusOptions="statusOptions" v-if="isShowWeiji">
      </weijiApplyDetail>
      <!--物品申购申请-->
      <goodsBuyDetail :goodsBuy="goodsBuyFormData" v-if="isShowGoodsBuy"></goodsBuyDetail>

      <!-- 公文详情 -->
      <documentApplyDetail :documentapplyFormData="documentapplyFormData" v-if="isShowDocumentApply" :fileList="fileList">
      </documentApplyDetail>
      <!--会议详情-->
      <conferenceroomDetail :ruleForm="conferenceroomData" :suppliesList="suppliesList" :checkedCities="checkedCities" 
      :locationList="locationList" :deptOptions="deptOptions" v-if="isShowcon"></conferenceroomDetail>
      <!--维修-->
      <repairOrderRecords :form="repairOrderRecordsData" v-if="isRepairOrderRecords"></repairOrderRecords>
       
      <!--审批记录-->
      <el-collapse>
        <el-collapse-item title="流程审批记录" name="1">
          <el-timeline style="margin-top: 5px;">
            <el-timeline-item v-for="(activity, index) in activities" :key="index"
              :color="activity.endTime?'#0bbd87':''" :timestamp="parseTime(activity.startTime)">
              <el-tag v-if="activity.endTime" >已处理</el-tag>
              <el-tag v-else type="info">未处理</el-tag>
              <el-tag v-if="activity.description.indexOf('【同意】')>=0" type="success"> 通过</el-tag>
              <el-tag v-if="activity.description.indexOf('【不同意】')>=0" type="warning">不通过</el-tag>
              <p style="color:#909399"><label>审批环节：</label>{{activity.taskName}}</p>
              <p style="color:#909399"> <label>审批人：</label>{{activity.assignee}}    </p>
              <p style="color:#909399"><label>审批意见：</label>{{activity.description}}</p>
            </el-timeline-item>
          </el-timeline>
        </el-collapse-item>
      </el-collapse>
      <el-divider content-position="left" v-if="activeName=='first'">审批</el-divider>
      <div v-if="activeName=='first'">
        <el-form :model="workflowformData" :rules="rules" ref="workflowformData" label-width="100px">
          <el-form-item label="审批状态" prop="flag">
            <el-radio label="1" v-model="workflowformData.flag">同意</el-radio>
            <el-radio label="0" v-model="workflowformData.flag">驳回</el-radio>
          </el-form-item>
          <!-- {{ studentLeaveSelfFormData.leaveTotalTime>1 }} -->
          <el-form-item label="下级审批人" prop="deptId" v-if="isShowApproved && workflowformData.flag=='1' ">
            <!-- <el-input v-model="leaveFormData.currApprovedBy" style="width:60%"/> -->
            <!-- <el-tag v-for="item in userList" :key="item.id" style="margin-left: 3px;">{{item.userName}}</el-tag> -->
            <!-- <el-button type="info" plain size="mini" icon="el-icon-plus" @click="handleUser">选择审批人</el-button> -->
            <!-- <el-button type="info" plain size="mini" icon="el-icon-delete" @click="clearUser" v-if="userList.length>0">清空审批人</el-button> -->
            <el-select v-model="workflowformData.deptId" placeholder="请选择" clearable>
              <el-option v-for="deptList in eadept" :key="deptList.deptName" :label="deptList.deptName" :value="deptList.deptId">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="审批意见" prop="applyDesc">
            <el-input type="textarea" v-model="workflowformData.applyDesc" style="width:90%"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer" v-if="activeName=='first'">
        <el-button type="primary" @click="submitForm" :loading="submitLoading">提 交</el-button>
        <el-button @click="handleClose">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :visible.sync="dialogVisibleUser" title="选择人员">
      <deptUser @getTaskUser="getApprovedUser" :multiple="false" v-if="dialogVisibleUser"></deptUser>
    </el-dialog>
  </div>
</template>

<script>
  import leaveApplyDetail from '../../components/workflow/leaveApplyDetail'
  import quitApplyDetail from '../../components/workflow/quitApplyDetail'
  import weijiApplyDetail from '../../components/workflow/weijiApplyDetail'
  import documentApplyDetail from "../../components/workflow/documentApplyDetail";
  import conferenceroomDetail from '../../components/workflow/conferenceroomDetail'
  import repairOrderRecords from '../../components/workflow/repairOrderRecords'
  import usePersonDetail from '../../components/workflow/usePersonDetail'
  import studentLeaveWithdrawalDetail from '../../components/workflow/studentLeaveWithdrawalDetail'
  import studentLeaveSelfDetail from '../../components/workflow/studentLeaveSelfDetail'
  import goodsBuyDetail from '../../components/workflow/goodsBuyDetail'
  import deptUser from '../../components/userSelect/deptUser.vue'
  
  import { getToken } from "@/utils/auth";
  import {
    findCurrUserToDoTasks, findLeaveApplyDetail, processWorkFlow, workFlowInfo, findQuitApplyDetail,
    weijiDetails, historyWorkFlowList, getDocumentApplyDetail, findMeetingApplyDetail,repairOrderRecordsDetail,
    findHistoryApproval ,usePersonApplyDetail,studentLeaveApplyDetail,goodsBuyApplyDetail,studentLeaveSelfApplyDetail
  } from "@/api/workflow/todo"
  import { locationTypeList} from "@/api/workflow/conferenCeroom";
  import { treeselectAll } from "@/api/system/dept";
  import {listDeptAll} from "@/api/system/dept";

  export default {
    name: "Config",
    components: {
      leaveApplyDetail,
      quitApplyDetail,
      weijiApplyDetail,
      documentApplyDetail,
      conferenceroomDetail,
      repairOrderRecords,
      usePersonDetail,
      studentLeaveWithdrawalDetail,
      goodsBuyDetail,
      studentLeaveSelfDetail,
      deptUser
    },
    data () {
      return {
        activeName:"first",
        submitLoading:false,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 总条数
        total: 0,
        // 参数表格数据
        deployList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 类型数据字典
        typeOptions: [],
        // 日期范围
        dateRange: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          applyID: undefined
        },
        dialogVisible: false,
        //请假表单数据
        leaveFormData: {},
        //公文表单数据
        documentapplyFormData: {},
        quitFormData: {},
        weijiFormData: {},
        workflowformData: {},
        conferenceroomData: {},
        usePersonFormData:{},
        studentLeaveFormData:{},
        goodsBuyFormData:{},
        studentLeaveSelfFormData:{},
        leaveTypeList: [],
        gradeOptions: [],
        statusOptions: [],
        isRepairOrderRecords:false,
        repairOrderRecordsData:{},
        arr: [],
        fileList: [],
        isShowLeave: false,
        isShowQuit: false,
        isShowWeiji: false,
        isShowcon: false,
        isShowDocumentApply: false,
        isShowUsePerson:false,
        isShowStudentLeave:false,
        isShowGoodsBuy:false,
        isShowStudentSelfLeave:false,
        rules: {
          flag: [{ required: true, message: "请选择审批状态", trigger: "blur" }],
          applyDesc: [{ required: true, message: "请填写审批意见", trigger: "blur" }],
          approvedBy:[{ required: true, message: "请选择审批人", trigger: "blur"}]
        },
        activities: [],
        checkedCities:[],
        suppliesList:[],
        approvalhistoryList:[],
        userList:[],
        dialogVisibleUser:false,
        isShowApproved:false,
        //审批部门 examine and approve dept
        eadept:[]
      };
    },
    computed: {
      headers () {
        return {
          'Authorization': getToken()
        }
      }
    },
    created () {
      this.getList();
      this.getDicts("leave_type").then(response => {
        this.leaveTypeList = response.data;
      });
      this.getDicts("VIOLATIVE_TAG").then(response => {
        this.statusOptions = response.data;
        console.log(this.statusOptions, 568)
      });
      this.getDicts("violative_level").then(response => {
        this.gradeOptions = response.data;
        console.log(this.gradeOptions, 565)
      });
      this.getDict()
      this.getDeptSelect()
    },
    methods: {
      getHistoryApprovalList(){

      },
      getDeptSelect() {
        listDeptAll().then(resp => {
            console.log(resp.data);
            this.eadept = resp.data
        })
      },
      /** 查询参数列表 */
      getList () {
        if(this.activeName=='first'){
          this.loading = true;
          findCurrUserToDoTasks(this.queryParams).then(response => {
              this.deployList = response.data.list;
              this.total = response.data.total;
              this.loading = false;
          }
          );
        }else{
          this.loading = true;
          findHistoryApproval(this.queryParams).then(response => {
              this.deployList = response.data.list;
              this.total = response.data.total;
              this.loading = false;
          })
        }
        
      },
      // 表单重置
      reset () {
        this.form = {
          id: undefined,
          paramName: undefined,
          paramKey: undefined,
          paramValue: undefined,
          paramType: "Y",
          remark: undefined
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery () {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery () {
        this.dateRange = [];
        this.resetForm("queryForm");
        this.handleQuery();
      },
      resetForm () {
        this.leaveFormData = {
          leaveStartTime: undefined,
          leaveEndTime: undefined,
          leaveTotalTime: undefined,
          leaveType: undefined,
          leaveRemarks: undefined,
        }
      },
      handleView (row) {

        this.leaveFormData = row
        this.dialogVisible = true
      },
      handleClose (done) {
        this.dialogVisible = false
      },
      handleApply (row) {
        this.resetForm()
        this.dialogVisible = true
        const appyType = row.processDefinitionId
        //离职
        if (appyType.indexOf("quitApply") >= 0) {
          this.isShowQuit = true
          this.isRepairOrderRecords = false
          this.isShowLeave = false
          this.isShowWeiji = false
          this.isShowcon = false,
          this.isShowUsePerson = false
          this.isShowStudentLeave = false
          this.isShowGoodsBuy = false
          this.isShowStudentSelfLeave = false
          this.getQuitApply(row.processInstanceId)
        }
        //请假
        if (appyType.indexOf("leaveApply") >= 0) {
          this.isShowLeave = true
          this.isRepairOrderRecords = false
          this.isShowQuit = false
          this.isShowWeiji = false
          this.isShowcon = false,
          this.isShowUsePerson = false
          this.isShowStudentLeave = false
          this.isShowGoodsBuy = false
          this.isShowStudentSelfLeave = false
          this.getLeaveApply(row.processInstanceId)
        }
        //违纪
        if (appyType.indexOf("violativeApply") >= 0) {
          this.isShowLeave = false
          this.isShowQuit = false
          this.isShowWeiji = true
          this.isRepairOrderRecords = false
          this.isShowcon = false,
          this.isShowUsePerson = false
          this.isShowStudentLeave = false
          this.isShowGoodsBuy = false
          this.isShowStudentSelfLeave = false
          this.getWeijiApply(row.processInstanceId)
        }
        //公文
        if (appyType.indexOf("documentApply") >= 0) {
          this.isShowDocumentApply = true;
          this.isRepairOrderRecords = false
          this.isShowLeave = false
          this.isShowQuit = false
          this.isShowWeiji = false
          this.isShowcon = false,
          this.isShowUsePerson = false
          this.isShowStudentLeave = false
          this.isShowGoodsBuy = false
          this.isShowStudentSelfLeave = false
          this.getDocumentApply(row.processInstanceId);
        }
        //会议
        if (appyType.indexOf("meetingApply") >= 0) {

          this.isRepairOrderRecords = false
          this.isShowLeave = false
          this.isShowQuit = false
          this.isShowWeiji = false
          this.isShowcon = true,
          this.isShowUsePerson = false
          this.isShowStudentLeave = false
          this.isShowGoodsBuy = false
          this.isShowStudentSelfLeave = false
          this.getLocationList()
          this.getconferenceroomApply(row.processInstanceId)
          this.getTreeselect()
        }
        //维修
        if(appyType.indexOf("repairApply") >= 0){
          this.isRepairOrderRecords = true
          this.isShowLeave = false
          this.isShowQuit = false
          this.isShowWeiji = false
          this.isShowcon = false,
          this.isShowUsePerson = false
          this.isShowStudentLeave = false
          this.isShowGoodsBuy = false
          this.isShowStudentSelfLeave = false
          this.repairOrder(row.processInstanceId)
        }
        //用人
        if(appyType.indexOf("usePersonApply") >= 0){
          this.isShowStudentSelfLeave = false
          this.isRepairOrderRecords = false
          this.isShowLeave = false
          this.isShowQuit = false
          this.isShowWeiji = false
          this.isShowcon = false,
          this.isShowStudentLeave = false
          this.isShowGoodsBuy = false
          this.isShowUsePerson = true
          
          this.usePersonApply(row.processInstanceId)
        }
        //学生请假(代提)
        if(appyType.indexOf("studentLeaveWithdrawal")>=0){
          this.isRepairOrderRecords = false
          this.isShowLeave = false
          this.isShowQuit = false
          this.isShowWeiji = false
          this.isShowcon = false,
          this.isShowUsePerson = false
          this.isShowGoodsBuy = false
          this.isShowStudentLeave = true
          this.isShowStudentSelfLeave = false
          this.studentLeaveApply(row.processInstanceId)
        }
        //学生请假(自提)
        if(appyType.indexOf("studentLeaveSelfApply")>=0){
          this.isRepairOrderRecords = false
          this.isShowLeave = false
          this.isShowQuit = false
          this.isShowWeiji = false
          this.isShowcon = false,
          this.isShowUsePerson = false
          this.isShowGoodsBuy = false
          this.isShowStudentLeave = false
          this.isShowStudentSelfLeave = true
          this.studentLeaveSelfApply(row.processInstanceId)
        }
        //物品申购
        if(appyType.indexOf("goodsBuyApply")>=0){
          this.isShowStudentSelfLeave = false
          this.isRepairOrderRecords = false
          this.isShowLeave = false
          this.isShowQuit = false
          this.isShowWeiji = false
          this.isShowcon = false,
          this.isShowUsePerson = false
          this.isShowStudentLeave = false
          this.isShowGoodsBuy = true
          this.goodsBuyApply(row.processInstanceId)
        }
        if(this.activeName=='first'){
          this.getWorkFlowInfo(row)
        }
        
        //查询历史审批记录
        this.historyWorkFlowList(row)

      },
      goodsBuyApply(processInstanceId){
        goodsBuyApplyDetail(processInstanceId).then(resp=>{
          this.goodsBuyFormData = resp.data
          if(resp.data.ccUsers){
            this.goodsBuyFormData.ccUserList = resp.data.ccUsers.split(',').map(item=>{
                return {userName:item}
            })
          }
        })
      },
      studentLeaveSelfApply(processInstanceId){
        //学生请假（代提）
        studentLeaveSelfApplyDetail(processInstanceId).then(resp=>{
          this.studentLeaveSelfFormData = resp.data
          if(resp.data.ccUsers){
            this.studentLeaveFormData.ccUserList = resp.data.ccUsers.split(',').map(item=>{
                return {userName:item}
            })
          }
        })
      },
      studentLeaveApply(processInstanceId){
        //学生请假（代提）
        studentLeaveApplyDetail(processInstanceId).then(resp=>{
          this.studentLeaveFormData = resp.data
          if(resp.data.ccUsers){
            this.studentLeaveFormData.ccUserList = resp.data.ccUsers.split(',').map(item=>{
                return {userName:item}
            })
          }
        })
      },
      usePersonApply(processInstanceId){
        usePersonApplyDetail(processInstanceId).then(resp=>{
          this.usePersonFormData = resp.data
          this.usePersonFormData.files=[]
          console.log(resp.data)
          if(resp.data.ccUsers){
            this.usePersonFormData.ccUserList = resp.data.ccUsers.split(',')
          }
          if(resp.data.fileList){
            const sFile = resp.data.fileList.split(',')
            for(let i=0;i<sFile.length;i++){
              this.usePersonFormData.files.push({
                url:sFile[i],
                name:resp.data.fileResourceNames.split(',')[i]
              })
  
            }
          }
        })
      },
      getQuitApply (processInstanceId) {
        findQuitApplyDetail(processInstanceId).then(resp => {
          this.quitFormData = resp.data
          const deptArray = resp.data.approvedDept.split(';')
          let approvedDeptArray = []
          for(let i=0;i<deptArray.length;i++){
            let dataIntAry = deptArray[i].split(',')
            approvedDeptArray.push(dataIntAry.map(item=>{
              return +item
            }))
          }
          this.quitFormData.approvedDeptModel = approvedDeptArray
          this.quitFormData.files=[]
          console.log(resp.data)
          if(resp.data.fileList){
            const sFile = resp.data.fileList.split(',')
            for(let i=0;i<sFile.length;i++){
              this.quitFormData.files.push({
                url:sFile[i],
                name:resp.data.fileResourceNames.split(',')[i]
              })
  
            }
          }
          if(resp.data.ccUsers){
            this.quitFormData.ccUserList = resp.data.ccUsers.split(',').map(item=>{
                return {userName:item}
            })
          }

        })
      },
      getLeaveApply (processInstanceId) {//查询请假申请单详情
        findLeaveApplyDetail(processInstanceId).then(resp => {
          this.leaveFormData = resp.data
          const deptArray = resp.data.approvedDept.split(';')
          let approvedDeptArray = []
          for(let i=0;i<deptArray.length;i++){
              let dataIntAry = deptArray[i].split(',')
              approvedDeptArray.push(dataIntAry.map(item=>{
              return +item
              }))
          }
          this.leaveFormData.approvedDeptModel = approvedDeptArray
          if(resp.data.ccUsers){
            this.leaveFormData.ccUserList = resp.data.ccUsers.split(',').map(item=>{
                return {userName:item}
            })
          }
        })
      },
      getWeijiApply (processInstanceId) {//查询违纪处理详情
        weijiDetails(processInstanceId).then(resp => {
          console.log(resp, 68686)
          this.weijiFormData = resp.data
          this.arr = resp.data.violativeTag.split(",")
          let filenameList = resp.data.fileName.split(',')
          let filePathList = resp.data.filePath.split(',')
          this.fileList = []
          for (let i = 0; i < filenameList.length; i++) {
            let fileJson = { name: filenameList[i], url: filePathList[i] }
            this.fileList.push(fileJson)
          }

        })
      },
      getWorkFlowInfo (row) {
        //查询流程信息
        const data = {
          processInstanceId: row.processInstanceId
        }
        workFlowInfo(data).then(resp => {
          this.workflowformData = resp.data
          this.workflowformData.taskId = row.taskId
          this.workflowformData.processDefinitionId = row.processDefinitionId
          //学生请假自提在班主任审批环节展示下级审批人选择

					if(this.workflowformData.currNode=='classTeacher' && this.workflowformData.applyID.indexOf('studentLeaveSelfApply')>=0){
						this.isShowApproved = true
					}
        })
      },
      submitForm () {

        this.$refs["workflowformData"].validate(valid => {
          if (valid) {
            this.submitLoading=true
            processWorkFlow(this.workflowformData).then(resp => {
              this.submitLoading = false
              console.log(resp.data)
              this.$message({ message: '提交成功', type: 'success' });
              this.dialogVisible = false
              this.getList()
            })
          }
        })
      },
      historyWorkFlowList (row) {
        //查询审批历史记录
        historyWorkFlowList({ processInstanceId: row.processInstanceId }).then(resp => {
          console.log(resp)
          this.activities = resp.data
        })
      },
      getDocumentApply (processInstanceId) {
        getDocumentApplyDetail(processInstanceId).then(resp => {
          this.documentapplyFormData = resp.data
          let filenameList = resp.data.fileName.split(',')
          let filePathList = resp.data.filePath.split(',')
          this.fileList = []
          for (let i = 0; i < filenameList.length; i++) {
            let fileJson = { name: filenameList[i], url: filePathList[i] }
            this.fileList.push(fileJson)
          }
        })
      },
      getconferenceroomApply (processInstanceId) {//查询会议室预定详情
        
        findMeetingApplyDetail(processInstanceId).then(resp => {
          console.log(resp, 5555)
          this.conferenceroomData = resp.data
          this.conferenceroomData.meetingTime=[this.conferenceroomData.meetingBeginTime,this.conferenceroomData.meetingEndTime]
          this.conferenceroomData.meetingDept = Number(resp.data.meetingDept)
          this.conferenceroomData.meetingLocation = Number(this.conferenceroomData.meetingLocation)
          this.conferenceroomData.personList = resp.data.personList.map(item => {
              return item.userName
          })
          this.checkedCities = resp.data.suppliesList.map(item => {
            return Number(item.suppliesId)
          })
          this.suppliesList.map(item=>{
            for(let i=0;i<resp.data.suppliesList.length;i++){
              if(item.id==resp.data.suppliesList[i].suppliesId){
                item.suppliesNum = resp.data.suppliesList[i].suppliesNum
                return item
              }
            }
          })
          })
      },
      getLocationList(){
        //查询会议室信息
        locationTypeList({locationType:"7"}).then(resp=>{
          this.locationList = resp.data
        })
      },
      getDict(){
        this.getDicts("meeting_supplies").then(response => {
          this.suppliesList = response.data;
          this.suppliesList = this.suppliesList.map(item => {
            this.$set(item, "suppliesNum", 1)
            return item;
          })
        });
      },
      getTreeselect(){
        treeselectAll().then(res=>{
          this.deptOptions = res.data
        })
      },
      //维修单
      repairOrder(processInstanceId){
        repairOrderRecordsDetail(processInstanceId).then(resp=>{
          this.repairOrderRecordsData = resp.data
          let files =[]
          if(resp.data.articleImage){
            const images =  resp.data.articleImage.split(',')
            console.log(images)
            for(let i=0;i<images.length;i++){
              if(images[i]){
                files.push({
                  name:images[i],
                  url: process.env.VUE_APP_BASE_API + "/school/file/"+images[i]
                })
              }
            }
            
          }
          this.repairOrderRecordsData.fileList= files
          console.log(this.repairOrderRecordsData,"维修单")
        })
      },
      handleClick(val){
        this.getList()
      },
      handleUser(){
        this.dialogVisibleUser = true
      },
      clearUser(){
        this.userList=[]
        this.workflowformData.approvedBy=null
      },
      getApprovedUser(data,isClose){
        this.userList = data
        if(data){
          let ccUser = []
          for(let i=0;i<data.length;i++){
            ccUser.push(data[i].userName)
          }
          this.workflowformData.approvedBy= ccUser.join(',')
          
        }
        this.$refs['workflowformData'].clearValidate('approvedBy')
        this.dialogVisibleUser = isClose
      },
    }
  };
</script>